/**************************************************************
 *   File:	Vector4.cpp
 * Author:	Andrew Thorpe
 *  Brief:	Full-featured 4 component vector class
 **************************************************************/
#include "StdAfx.h"
#include "Vector4.h"

#include <math.h>

using namespace Fossil;
Vector4& Vector4::operator = (const Vector4& rhs)
{
	m_x = rhs.m_x;
	m_y = rhs.m_y;
	m_z = rhs.m_z;
	m_w = rhs.m_w;
	return *this;
}

Vector4 Vector4::operator + (const Vector4& rhs) const
{
	return Vector4(m_x + rhs.m_x, m_y + rhs.m_y, m_z + rhs.m_z);
}

void Vector4::operator += (const Vector4& rhs)
{
	m_x += rhs.m_x;
	m_y += rhs.m_y;
	m_z += rhs.m_z;
}

Vector4 Vector4::operator + (float rhs) const
{
	return Vector4(m_x + rhs, m_y + rhs, m_z + rhs);
}

void Vector4::operator += (float rhs)
{
	m_x += rhs;
	m_y += rhs;
	m_z += rhs;
}

Vector4 Vector4::operator - (const Vector4& rhs) const
{
	return Vector4(m_x - rhs.m_x, m_y - rhs.m_y, m_z - rhs.m_z);
}

void Vector4::operator -= (const Vector4& rhs)
{
	m_x -= rhs.m_x;
	m_y -= rhs.m_y;
	m_z -= rhs.m_z;
}

Vector4 Vector4::operator - (float rhs) const
{
	return Vector4(m_x - rhs, m_y - rhs, m_z - rhs);
}

void Vector4::operator -= (float rhs)
{
	m_x -= rhs;
	m_y -= rhs;
	m_z -= rhs;
}

Vector4 Vector4::operator /  (const Vector4& rhs) const
{
	return Vector4(m_x / rhs.m_x, m_y / rhs.m_y, m_z / rhs.m_z);
}

void Vector4::operator /= (const Vector4& rhs)
{
	m_x /= rhs.m_x;
	m_y /= rhs.m_y;
	m_z /= rhs.m_z;
}

Vector4 Vector4::operator /  (float rhs) const
{
	float div = 1.0f / rhs;
	return Vector4(m_x * div, m_y * div, m_z * div);
}

void Vector4::operator /= (float rhs)
{
	float div = 1.0f / rhs;
	m_x *= div;
	m_y *= div;
	m_z *= div;
}

Vector4 Vector4::operator * (const Vector4& rhs) const
{
	return Vector4(m_x * rhs.m_x, m_y * rhs.m_y, m_z * rhs.m_z);
}

void Vector4::operator *= (const Vector4& rhs)
{
	m_x *= rhs.m_x;
	m_y *= rhs.m_y;
	m_z *= rhs.m_z;
}

Vector4 Vector4::operator * (float rhs) const
{
	return Vector4(m_x * rhs, m_y * rhs, m_z * rhs);
}

void Vector4::operator *= (float rhs)
{
	m_x *= rhs;
	m_y *= rhs;
	m_z *= rhs;
}

bool Vector4::operator == (const Vector4& rhs) const
{
	return ( (m_x == rhs.m_x) && (m_y == rhs.m_y) && (m_z == rhs.m_z) && (m_w == rhs.m_w) );
}

bool Vector4::operator != (const Vector4& rhs) const
{
	return ( (m_x != rhs.m_x) && (m_y != rhs.m_y) && (m_z != rhs.m_z) && (m_w != rhs.m_w) );
}

float Vector4::Dot(const Vector4& rhs) const
{
	return ( ( m_x * rhs.m_x ) + ( m_y * rhs.m_y ) + ( m_z * rhs.m_z ) );
}

Vector4 Vector4::Cross(const Vector4& rhs) const
{
	return Vector4( ( (m_y * rhs.m_z) - (m_z * rhs.m_y) ),
					( (m_z * rhs.m_x) - (m_x * rhs.m_z) ),
					( (m_x * rhs.m_y) - (m_y * rhs.m_x) ) );
}

float Vector4::Length() const
{
	return sqrt( ( m_x * m_x ) + ( m_y * m_y ) + ( m_z * m_z ) );
}

float Vector4::SquaredLength() const
{
	return ( ( m_x * m_x ) + ( m_y * m_y ) + ( m_z * m_z ) );
}

void Vector4::Normalise()
{
	float len = 1.0f / Length();
	m_x *= len;
	m_y *= len;
	m_z *= len;
}

Vector4 Vector4::Normalised() const
{
	float len = 1.0f / Length();
	return Vector4(m_x * len, m_y * len, m_z * len);
}

Vector4 Vector4::UnitX()
{
	return Vector4(1.0f, 0.0f, 0.0f);
}

Vector4 Vector4::UnitY()
{
	return Vector4(0.0f, 1.0f, 0.0f);
}

Vector4 Vector4::UnitZ()
{
	return Vector4(0.0f, 0.0f, 1.0f);
}

Vector4 Vector4::Zero()
{
	return Vector4(0.0f, 0.0f, 0.0f);
}
